home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / Mesa-3.0 / SRC / DOS / DOSMESA.C < prev   
Encoding:
C/C++ Source or Header  |  1997-06-20  |  32.2 KB  |  1,500 lines

  1. /* $Id: dosmesa.c 1.3 1997/05/28 16:13:45 Charlie Exp Charlie $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.3
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: dosmesa.c $
  26.  *
  27.  * Revision 1.5  1997/06/19  22:00:00  Brian Paul
  28.  * Removed all ColorShift stuff
  29.  *
  30.  * Revision 1.4  1997/06/03  19:00:00  Brian Paul
  31.  * Replaced VB->Unclipped[] with VB->ClipMask[]
  32.  *
  33.  * Revision 1.3  1997/05/28  07:00:00  Phil Frisbie, Jr.
  34.  * Now pass red/green/blue/alpha bits to gl_create_visual()
  35.  * Fixed DJGPP mode 13 support.
  36.  *
  37.  * Revision 1.2  1996/12/08  16:13:45  Charlie
  38.  * Added VESA support via Scitechs SVGA kit.
  39.  *
  40.  * Revision 1.1  1996/12/08  16:09:52  Charlie
  41.  * Initial revision
  42.  *
  43.  */
  44.  
  45.  
  46. /*
  47.  * DOS VGA/VESA/MGL/Mesa interface.
  48.  *
  49.  */
  50.  
  51. /*
  52.  *
  53.  * TODO: (cw)
  54.  *     Improve the colour matcher for rgb non vesa modes, its pretty bad and incorrect
  55.  *     Keyboard interrupt.
  56.  *  Comments and tidy up.
  57.  *  Add support for VESA without SVGAKIT.
  58.  *  DirectX Support.
  59.  *  Better GLIDE Support.
  60.  *  Clear up the #ifdef madness.
  61.  */
  62.  
  63. #ifdef DOSVGA
  64.  
  65. #if defined(DOSVGA) && !defined(GLIDE) && defined(DJGPP) && !defined(UNIVBE) && !defined(MGL)
  66.  
  67. /* Should help cut down on the crazy #if`s */
  68. #define MODE13 1
  69.  
  70. #else
  71. #undef MODE13
  72. #endif
  73.  
  74. #include <stdio.h>
  75. #include <stdlib.h>
  76. #include <string.h>
  77. #include <string.h>
  78. #include <dos.h>
  79.  
  80. #ifdef DJGPP
  81. #include <go32.h>
  82. #endif
  83.  
  84. #ifdef MGL
  85. #include <mgraph.h>
  86. #endif
  87.  
  88. #include "GL/DOSmesa.h"
  89. #include "context.h"
  90. #include "matrix.h"
  91. #include "types.h"
  92.  
  93. #ifdef GLIDE
  94.  
  95. static void glideshutdown( void );
  96. #include "vb.h"
  97. #include "glide.h"
  98.  
  99. /* the glide modes available, set one */
  100.  
  101. //#define GLIDE_MODE GR_RESOLUTION_
  102. #define GLIDE_MODE GR_RESOLUTION_800x600
  103. //#define GLIDE_MODE GR_RESOLUTION_640x480
  104.  
  105. static GrVertex gr_vtx,gr_vtx1,gr_vtx2;
  106.  
  107. #endif
  108.  
  109. #ifdef UNIVBE
  110. /* You get this file from Scitechs VESA development kit */
  111. #include "svga.h"
  112.  
  113. /*
  114.    Set these to the VESA mode you require, the first is for 256 colour modes,
  115.    the other is High colour modes, they must both be the same XRes and YRes.
  116.  */
  117.  
  118. #define VESA_256COLOUR_MODE 0x11c
  119. #define VESA_HICOLOUR_MODE 0x11f
  120.  
  121. #endif
  122.  
  123. struct DOSmesa_context {
  124.    GLcontext *gl_ctx;            /* the core Mesa context */
  125.    GLvisual *gl_vis;                /* describes the color buffer */
  126.    GLframebuffer *gl_buffer;    /* the ancillary buffers */
  127.    GLuint index;                    /* current color index */
  128.    GLint red, green, blue;        /* current rgb color */
  129.    GLint width, height;            /* size of color buffer */
  130.    GLint depth;                    /* bits per pixel (8,16,24 or 32) */
  131. };
  132.  
  133. static DOSMesaContext DOSMesa = NULL;    /* the current context */
  134.  
  135. #ifdef UNIVBE
  136. SV_devCtx *DC=NULL;
  137. int useLinear = TRUE;
  138. SV_modeInfo *mi=NULL;
  139. unsigned long modeNumber = 0;
  140.  
  141. int activePage = 0;
  142. int visualPage = 1;
  143.  
  144. #endif
  145.  
  146. #if defined(MODE13)
  147.  
  148. /* DOSVGA With no UniVBE support */
  149.  
  150. unsigned char *video_buffer;
  151.  
  152. #define VID_BUF(x,y) *(video_buffer+x+(y*320))
  153.  
  154. #if defined(__WATCOMC__) && defined(__386__) && defined(__DOS__)
  155.  
  156. void setupcopy(void);
  157. void copyscr(void);
  158.  
  159. /* Watcom C specfic, screen copy and clear */
  160.  
  161. #pragma aux setupcopy = \
  162.     ".386P"\
  163.     "push ebp" \
  164.     "mov esi,video_buffer" \
  165.     "mov edi,0xa0000" \
  166.     "mov ecx,2000" \
  167.     "xor ebp,ebp";
  168.  
  169. #pragma aux copyscr = \
  170.     ".386P" \
  171.     "lop1: mov eax,[esi]"\
  172.     "mov ebx,[esi+4]"\
  173.     "mov edx,[esi+8]"\
  174.     "mov [edi],eax"\
  175.     "mov eax,[esi+12]"\
  176.     "mov dword ptr [esi],ebp"\
  177.     "mov dword ptr [esi+4],ebp"\
  178.     "mov dword ptr [esi+8],ebp"\
  179.     "mov dword ptr [esi+12],ebp"\
  180.     "mov [edi+4],ebx"\
  181.     "mov [edi+8],edx"\
  182.     "mov [edi+12],eax"\
  183.     "mov eax,[esi+16]"\
  184.     "mov ebx,[esi+4+16]"\
  185.     "mov edx,[esi+8+16]"\
  186.     "mov [edi+16],eax"\
  187.     "mov eax,[esi+12+16]"\
  188.     "mov dword ptr [esi+16],ebp"\
  189.     "mov dword ptr [esi+4+16],ebp"\
  190.     "mov dword ptr [esi+8+16],ebp"\
  191.     "mov dword ptr [esi+12+16],ebp"\
  192.     "mov [edi+4+16],ebx"\
  193.     "mov [edi+8+16],edx"\
  194.     "mov [edi+12+16],eax"\
  195.     "add esi,32"\
  196.     "add edi,32"\
  197.     "dec ecx"\
  198.     "jnz lop1"\
  199.     "pop ebp"\
  200.     modify exact [edi esi eax ebx ecx] ;
  201.  
  202. #endif // WATCOM
  203.  
  204. #endif // MODE13
  205.  
  206. /*
  207.  * Convert Mesa window Y coordinate to VGA screen Y coordinate:
  208.  */
  209. #define FLIP(Y)  (DOSMesa->height-(Y)-1)
  210.  
  211. unsigned short vga_cindex = 32768 ;
  212.  
  213. static points_func choose_points_function( void );
  214. static line_func choose_line_function( void );
  215. static triangle_func choose_polygon_function( void );
  216. static void fast_tri(GLcontext *ctx,GLuint v0, GLuint v1, GLuint v2, GLuint pv );
  217.  
  218. static points_func choose_points_function( void )
  219. {
  220.     return NULL;
  221. }
  222.  
  223. static line_func choose_line_function( void )
  224. {
  225.     return NULL;
  226. }
  227.  
  228. static triangle_func choose_triangle_function( void )
  229. {
  230.     #if defined(MODE13)
  231.         return    NULL;
  232.     #endif
  233.  
  234.     #if defined(GLIDE)
  235.         return fast_tri;
  236.     #endif
  237.  
  238.     return    NULL;
  239. }
  240.  
  241.  
  242. #if defined(MODE13)
  243.  
  244. void setgfxmode(void);
  245. void settextmode(void);
  246.  
  247. #ifndef DJGPP
  248. #pragma aux setgfxmode = \
  249.     "mov    ax,13h" \
  250.     "int    10h" \
  251.     modify [eax];
  252.  
  253. #pragma aux settextmode = \
  254.     "mov    ax,3h" \
  255.     "int    10h" \
  256.     modify [eax];
  257. #else
  258. void setgfxmode(void)
  259. {
  260.     union REGS in_regs,out_regs;
  261.  
  262.     in_regs.x.ax = 0x13;
  263.     int386(0x10,&in_regs,&out_regs);
  264. }
  265.  
  266. void settextmode(void)
  267. {
  268.     union REGS in_regs,out_regs;
  269.  
  270.     in_regs.x.ax = 0x3;
  271.     int386(0x10,&in_regs,&out_regs);
  272. }
  273.  
  274. #endif
  275.  
  276. int set_video_mode(unsigned short x,unsigned short y,char mode)
  277. {
  278.     setgfxmode();
  279.     return 1;    /* likelyhood of this failing is very small */
  280. }
  281.  
  282. void restore_video_mode(void)
  283. {
  284.     settextmode();
  285. }
  286.  
  287. int vga_getcolors(void)
  288. {
  289.     return vga_cindex;
  290. }
  291.  
  292. int vga_getxdim(void)
  293. {
  294.     return 320;
  295. }
  296.  
  297. int vga_getydim(void)
  298. {
  299.     return 200;
  300. }
  301.  
  302. static unsigned short num_rgb_alloc = 1; /* start from 1, zero is black */
  303.  
  304. /* an unlikely colour */
  305. static unsigned char last_r=1,last_g=255,last_b=99;
  306.  
  307. extern void set_onecolor(int index,int R,int G,int B);
  308.  
  309. static unsigned char rgbtable[64][64][64];
  310.  
  311. void vga_setrgbcolor(int r,int g,int b)
  312. {
  313.  
  314. /*
  315.  * make this into a translation table
  316.  */
  317.  
  318.     DOSMesa->red = r;
  319.     DOSMesa->green = g ;
  320.     DOSMesa->blue = b ;
  321.  
  322.     r/=4; g/=4; b/=4;
  323.  
  324.     if( (r == last_r) && (g == last_g) && (b == last_b) ) return;
  325.  
  326.     last_r = r ;
  327.     last_g = g ;
  328.     last_b = b ;
  329.  
  330.     if(r+g+b == 0 ) {
  331.         DOSMesa->index = 0 ;
  332.         return ;
  333.     }
  334.  
  335.     if( rgbtable[r][g][b] == 0 ) {
  336.         /* not allocated yet */
  337.         if(num_rgb_alloc<256) {
  338.             DOSMesa->index = num_rgb_alloc;
  339.             set_onecolor(num_rgb_alloc,r,g,b);
  340.             rgbtable[r][g][b] = num_rgb_alloc;
  341.             num_rgb_alloc++;
  342.             return;
  343.  
  344.         } else {
  345.             /* need to search for a close colour */
  346.             {
  347.                 unsigned short pass ;
  348.  
  349.                 for(pass=0;pass<64;pass++) {
  350.                     if(r-pass>0) {
  351.                         if( rgbtable[r-pass][g][b] !=0 ) {
  352.                             rgbtable[r][g][b] = rgbtable[r-pass][g][b];
  353.                             DOSMesa->index = rgbtable[r-pass][g][b];
  354.                             return;
  355.                         }
  356.                     }
  357.                     if(r+pass<64) {
  358.                         if( rgbtable[r+pass][g][b] !=0 ) {
  359.                             rgbtable[r][g][b] = rgbtable[r+pass][g][b];
  360.                             DOSMesa->index = rgbtable[r+pass][g][b];
  361.                             return;
  362.                         }
  363.                     }
  364.                 }
  365.             }
  366.             rgbtable[r][g][b] = rand()%255;
  367.         }
  368.     }
  369.     DOSMesa->index = rgbtable[r][g][b];
  370. }
  371.  
  372. #if defined(DJGPP)
  373. static int dos_seg;
  374. #endif
  375.  
  376. void vga_clear(void)
  377. {
  378.  
  379. /* Check if we`re using watcom and DOS */
  380. #if defined(__WATCOMC__) && defined(__386__) && defined(__DOS__)
  381.     setupcopy();
  382.     copyscr();
  383. #else
  384.  
  385. #if defined (DJGPP)
  386.  
  387.  
  388.     asm ("
  389.         pusha
  390.         pushw    %es
  391.  
  392.         movw    _dos_seg, %es
  393.  
  394.         movl    _video_buffer, %esi
  395.         movl    $0xa0000, %edi
  396.  
  397.         movl    $64000, %ecx
  398.  
  399.         rep    ; movsb
  400.  
  401.         popw    %es
  402.         popa
  403.     ");
  404.  
  405. #else
  406.  
  407.     /* copy the RAM buffer to the Video memory */
  408.     memcpy((unsigned char *)0xa0000,video_buffer, vga_getxdim()*vga_getydim() );
  409.  
  410. #endif //DJGPP
  411.  
  412.     /* clear the RAM buffer */
  413.     memset(video_buffer,0, vga_getxdim()*vga_getydim() );
  414.  
  415. #endif //WATCOMC
  416.  
  417. }
  418.  
  419. #ifndef DEBUG
  420. #define vga_drawpixel(x,y) { VID_BUF(x,y) = DOSMesa->index; }
  421. #else
  422. void vga_drawpixel(x,y)
  423. {
  424.     VID_BUF(x,y) = DOSMesa->index;
  425. }
  426. #endif
  427.  
  428. int vga_getpixel(int x,int y)
  429. {
  430.     return 1;
  431. }
  432.  
  433. void vga_flip(void)
  434. {
  435.  
  436. }
  437.  
  438. void vga_setcolor(int index)
  439. {
  440.     /* does something, what i`ve no idea */
  441.     DOSMesa->index = index;
  442.  
  443. }
  444.  
  445. #endif
  446.  
  447. #if defined(UNIVBE)
  448.  
  449. /* UniVBE VESA support */
  450.  
  451. void set_video_mode(unsigned short x,unsigned short y,char mode)
  452. {
  453.     if( setup_vesa_mode(x,y,mode) == FALSE ) {
  454.         fprintf(stderr,"VESA: Set mode failed\n");
  455.         exit(1);
  456.     }
  457. }
  458.  
  459. /*
  460.    This is problematic as we don`t know what resolution the user program
  461.    wants when we reach here. This is why the 256 colour and HiColour modes
  462.     should be the same resolution, perhaps i`ll make this an environment
  463.     variable
  464.  */
  465.  
  466.  
  467. void check_mi(void)
  468. {
  469.     if(mi!=0) return;
  470.  
  471.     if(DC==NULL) {
  472.         DC = SV_init( TRUE );
  473.     }
  474.  
  475.     if(modeNumber == 0 ) {
  476.         modeNumber = VESA_HICOLOUR_MODE;
  477.     }
  478.  
  479.     SV_getModeInfo(modeNumber,mi);
  480.  
  481.     return;
  482. }
  483.  
  484. int setup_vesa_mode(short height,short width,short depth)
  485. {
  486.     if(DC==NULL) {
  487.         DC = SV_init( TRUE );
  488.         /* how many bits per pixel */
  489.         if( depth == 0)
  490.             modeNumber = VESA_256COLOUR_MODE;
  491.         else
  492.             modeNumber = VESA_HICOLOUR_MODE;
  493.     }
  494.  
  495.     /* Check if correct VESA Version is available */
  496.     if( !DC || DC->VBEVersion < 0x0102) {
  497.         fprintf(stderr,"Require a VESA VBE version 1.2 or higher\n");
  498.         return FALSE;
  499.     }
  500.  
  501.     /* Check for LFB Supprt */
  502.     if(DC->VBEVersion < 0x0200 ) {
  503.         useLinear = FALSE;
  504.     } else {
  505.         useLinear = TRUE ;
  506.     }
  507.  
  508.      /* Get desired mode info */
  509.    if(!SV_getModeInfo( modeNumber, mi))
  510.         return FALSE;
  511.  
  512.     /* Set VESA mode */
  513.     if(!SV_setMode(modeNumber | svMultiBuffer, FALSE, TRUE, mi->NumberOfPages) )
  514.         return FALSE;
  515.  
  516.     return TRUE;
  517. }
  518.  
  519. void restore_video_mode(void)
  520. {
  521.     SV_restoreMode();
  522. }
  523.  
  524. void vga_clear(void)
  525. {
  526.     SV_clear(0);
  527. }
  528.  
  529. void vga_flip(void)
  530. {
  531.     activePage = 1-activePage;
  532.     visualPage = 1-activePage;
  533.  
  534.     SV_setActivePage(activePage);
  535.  
  536.     /*
  537.        Change false to true if you`re getting flickering
  538.        even in double buffer mode, ( sets wait for Vertical retrace  )
  539.     */
  540.     SV_setVisualPage(visualPage,false);
  541. }
  542.  
  543. int vga_getcolors(void)
  544. {
  545.     check_mi();
  546.     switch ( mi->BitsPerPixel ) {
  547.         case 8:
  548.             return 256;
  549.         case 15:
  550.         case 16:
  551.             return 32768;
  552.         default:
  553.             return 64000;
  554.      }
  555. }
  556.  
  557. int vga_getxdim(void)
  558. {
  559.     check_mi();
  560.     return mi->XResolution;
  561. }
  562.  
  563. int vga_getydim(void)
  564. {
  565.     check_mi();
  566.     return mi->YResolution;
  567. }
  568.  
  569. unsigned long current_color = 255;
  570.  
  571. void vga_setrgbcolor(int r,int g,int b)
  572. {
  573.     DOSMesa->red = r;
  574.     DOSMesa->green = g ;
  575.     DOSMesa->blue = b ;
  576.     current_color = SV_rgbColor(r,g,b);
  577. }
  578.  
  579. void vga_setcolor(int index)
  580. {
  581.     DOSMesa->index = index;
  582.     current_color = index;
  583. }
  584.  
  585. void vga_drawpixel(x,y)
  586. {
  587.     SV_putPixel(x,y,current_color);
  588. }
  589.  
  590. /* TODO: */
  591. int vga_getpixel(x,y)
  592. {
  593. /*    return (int)SV_getPixel(x,y); */
  594.     fprintf(stderr,"vga_getpixel: Not implemented yet\n");
  595.     return 1;
  596. }
  597.  
  598. /* End of UNIVBE section */
  599. #endif
  600.  
  601. /* Scitechs MegaGraphicsLibrary http://www.scitechsoft.com/ */
  602.  
  603. #if defined(MGL)
  604.  
  605. /* MGL support */
  606. struct MI {
  607.     unsigned short BitsPerPixel;
  608.     unsigned long XResolution;
  609.     unsigned long YResolution;
  610. };
  611.  
  612. struct MI*mi;
  613.  
  614. static MGLDC*DC;
  615. static int activePage = 0;
  616. static int visualPage = 1;
  617. static int modeNumber = 0;
  618.  
  619. void set_video_mode(unsigned short xres,unsigned short yres,char mode)
  620. {
  621.     int     i,driver = grDETECT,dmode = grDETECT;
  622.     event_t evt;
  623.  
  624.     /* Start the MGL with only the SVGA 16m driver active */
  625.     MGL_registerDriver(MGL_SVGA16NAME,SVGA16_driver);
  626.     if (!MGL_init(&driver,&dmode,"..\\..\\"))
  627.         MGL_fatalError(MGL_errorMsg(MGL_result()));
  628.     if ((DC = MGL_createDisplayDC(false)) == NULL)
  629.         MGL_fatalError(MGL_errorMsg(MGL_result()));
  630.     MGL_makeCurrentDC(DC);
  631. }
  632.  
  633. /*
  634.    This is problematic as we don`t know what resolution the user program
  635.    wants when we reach here. This is why the 256 colour and HiColour modes
  636.     should be the same resolution, perhaps i`ll make this an environment
  637.     variable
  638.  */
  639.  
  640. #define MGL_HICOLOUR_MODE 0
  641.  
  642.  
  643. void check_mi(void)
  644. {
  645.     if(mi!=0) return;
  646.  
  647.     if(DC==NULL) {
  648. //        DC = SV_init( TRUE );
  649.     }
  650.  
  651.     if(modeNumber == 0 ) {
  652.         modeNumber = MGL_HICOLOUR_MODE;
  653.     }
  654.  
  655. //    SV_getModeInfo(modeNumber,mi);
  656.  
  657.     return;
  658. }
  659.  
  660. void restore_video_mode(void)
  661. {
  662.     MGL_exit();
  663. }
  664.  
  665. void vga_clear(void)
  666. {
  667.     MGL_clearDevice();
  668. }
  669.  
  670. void vga_flip(void)
  671. {
  672.     activePage = 1-activePage;
  673.     visualPage = 1-activePage;
  674.  
  675. //    SV_setActivePage(activePage);
  676.  
  677.     /*
  678.        Change false to true if you`re getting flickering
  679.        even in double buffer mode, ( sets wait for Vertical retrace  )
  680.     */
  681. //    SV_setVisualPage(visualPage,false);
  682. }
  683.  
  684. int vga_getcolors(void)
  685. {
  686.     check_mi();
  687.     switch ( mi->BitsPerPixel ) {
  688.         case 8:
  689.             return 256;
  690.         case 15:
  691.         case 16:
  692.             return 32768;
  693.         default:
  694.             return 64000;
  695.      }
  696. }
  697.  
  698. int vga_getxdim(void)
  699. {
  700.     check_mi();
  701.     return mi->XResolution;
  702. }
  703.  
  704. int vga_getydim(void)
  705. {
  706.     check_mi();
  707.     return mi->YResolution;
  708. }
  709.  
  710. unsigned long current_color = 255;
  711.  
  712. void vga_setrgbcolor(int r,int g,int b)
  713. {
  714.     DOSMesa->red = r;
  715.     DOSMesa->green = g ;
  716.     DOSMesa->blue = b ;
  717.     current_color = MGL_rgbColor(DC,r,g,b);
  718. }
  719.  
  720. void vga_setcolor(int index)
  721. {
  722.     DOSMesa->index = index;
  723.     current_color = index;
  724. }
  725.  
  726. void vga_drawpixel(x,y)
  727. {
  728.     MGL_pixelCoord(x,y);
  729. }
  730.  
  731. /* TODO: */
  732. int vga_getpixel(x,y)
  733. {
  734. /*    return (int)SV_getPixel(x,y); */
  735.     fprintf(stderr,"vga_getpixel: Not implemented yet\n");
  736.     return 1;
  737. }
  738.  
  739. /* End of UNIVBE section */
  740. #endif
  741.  
  742. #ifdef GLIDE
  743.  
  744. /* GLIDE support */
  745.  
  746. static GrHwConfiguration hwconfig;
  747.  
  748. void set_video_mode(unsigned short x,unsigned short y,char mode)
  749. {
  750.     grGlideInit();
  751.     if( grSstQueryHardware( &hwconfig ) ) {
  752.         grSstSelect( 0 ) ;
  753.         if( !grSstOpen( GLIDE_MODE,
  754.                             GR_REFRESH_60Hz,
  755.                             GR_COLORFORMAT_ABGR,
  756.                             GR_ORIGIN_UPPER_LEFT,
  757.                             GR_SMOOTHING_ENABLE,
  758.                             2 ) ) {
  759.             fprintf(stderr,"Detected 3DFX board, but couldn`t initialize!");
  760.             exit(1);
  761.         }
  762.  
  763.         grBufferClear( 0, 0, GR_WDEPTHVALUE_FARTHEST);
  764.  
  765.         grDisableAllEffects();
  766.         atexit( glideshutdown );
  767.  
  768. //        guColorCombineFunction( GR_COLORCOMBINE_ITRGB );
  769. //        grTexCombineFunction( GR_TMU0, GR_TEXTURECOMBINE_ZERO);
  770.     }
  771. }
  772.  
  773. void restore_video_mode(void)
  774. {
  775. }
  776.  
  777. static void glideshutdown( void )
  778. {
  779.     grGlideShutdown() ;
  780. }
  781.  
  782. void vga_clear(void)
  783. {
  784.     grBufferSwap(0);
  785.     grBufferClear( 0, 0, GR_WDEPTHVALUE_FARTHEST);
  786. }
  787.  
  788. void vga_flip(void)
  789. {
  790. }
  791.  
  792. int vga_getcolors(void)
  793. {
  794.     return 32768;
  795. }
  796.  
  797. int vga_getxdim(void)
  798. {
  799. #if GLIDE_MODE == GR_RESOLUTION_800x600
  800.         return 800;
  801. #else
  802.         return 640;
  803. #endif
  804. }
  805.  
  806. int vga_getydim(void)
  807. {
  808. #if GLIDE_MODE == GR_RESOLUTION_800x600
  809.         return 600;
  810. #else
  811.         return 480;
  812. #endif
  813. }
  814.  
  815. unsigned long current_color = 255;
  816.  
  817. void vga_setrgbcolor(int r,int g,int b)
  818. {
  819.     DOSMesa->red = r;
  820.     DOSMesa->green = g ;
  821.     DOSMesa->blue = b ;
  822. }
  823.  
  824. void vga_setcolor(int index)
  825. {
  826.     DOSMesa->index = index;
  827. }
  828.  
  829. void vga_drawpixel(x,y)
  830. {
  831.  
  832.     gr_vtx.x = x;
  833.     gr_vtx.y = y;
  834.     gr_vtx.z = 0;
  835.     gr_vtx.r    = DOSMesa->red;
  836.     gr_vtx.g    = DOSMesa->green;
  837.     gr_vtx.b    = DOSMesa->blue;
  838.  
  839.     grDrawPoint( &gr_vtx );
  840. }
  841.  
  842. static void fast_tri(GLcontext *ctx,GLuint v0, GLuint v1, GLuint v2, GLuint pv )
  843. {
  844.    struct vertex_buffer *VB = ctx->VB;
  845.  
  846.     gr_vtx.z = 0;
  847.     gr_vtx1.z = 0;
  848.     gr_vtx2.z = 0;
  849.  
  850.    if (VB->MonoColor) {
  851.           gr_vtx.r = DOSMesa->red;
  852.        gr_vtx.g = DOSMesa->green;
  853.        gr_vtx.b = DOSMesa->blue;
  854.        gr_vtx1.r = DOSMesa->red;
  855.        gr_vtx1.g = DOSMesa->green;
  856.        gr_vtx1.b = DOSMesa->blue;
  857.        gr_vtx2.r = DOSMesa->red;
  858.        gr_vtx2.g = DOSMesa->green;
  859.        gr_vtx2.b = DOSMesa->blue;
  860.    } else {
  861.         if(ctx->Light.ShadeModel == GL_SMOOTH ) {
  862.               gr_vtx.r  = FixedToInt( VB->Color[v0][0] );
  863.               gr_vtx.g  = FixedToInt( VB->Color[v0][1] );
  864.               gr_vtx.b  = FixedToInt( VB->Color[v0][2] );
  865.  
  866.               gr_vtx1.r = FixedToInt( VB->Color[v1][0] );
  867.               gr_vtx1.g = FixedToInt( VB->Color[v1][1] );
  868.               gr_vtx1.b = FixedToInt( VB->Color[v1][2] );
  869.  
  870.               gr_vtx2.r = FixedToInt( VB->Color[v2][0] );
  871.               gr_vtx2.g = FixedToInt( VB->Color[v2][1] );
  872.               gr_vtx2.b = FixedToInt( VB->Color[v2][2] );
  873.         } else {
  874.               gr_vtx.r  = VB->Color[pv][0];
  875.               gr_vtx.g  = VB->Color[pv][1];
  876.               gr_vtx.b  = VB->Color[pv][2];
  877.  
  878.               gr_vtx1.r = VB->Color[pv][0];
  879.               gr_vtx1.g = VB->Color[pv][1];
  880.               gr_vtx1.b = VB->Color[pv][2];
  881.  
  882.               gr_vtx2.r = VB->Color[pv][0];
  883.               gr_vtx2.g = VB->Color[pv][1];
  884.               gr_vtx2.b = VB->Color[pv][2];
  885.         }
  886.     }
  887.  
  888.    gr_vtx.x  =       (VB->Win[v0][0] );
  889.    gr_vtx.y  = FLIP( (VB->Win[v0][1] ) );
  890.    gr_vtx1.x =       (VB->Win[v1][0] );
  891.    gr_vtx1.y = FLIP( (VB->Win[v1][1] ) );
  892.    gr_vtx2.x =       (VB->Win[v2][0] );
  893.    gr_vtx2.y = FLIP( (VB->Win[v2][1] ) );
  894.  
  895.     if(gr_vtx.x <0 || gr_vtx.x > 639 )
  896.         return;
  897.     if(gr_vtx1.x <0 || gr_vtx1.x > 639 )
  898.         return;
  899.     if(gr_vtx2.x <0 || gr_vtx2.x > 639 )
  900.         return;
  901.  
  902.     if(gr_vtx.y <0 || gr_vtx.y > 479 )
  903.         return;
  904.     if(gr_vtx1.y <0 || gr_vtx1.y > 479 )
  905.         return;
  906.     if(gr_vtx2.y <0 || gr_vtx2.y > 479 )
  907.         return;
  908.  
  909.     grDrawTriangle( &gr_vtx,&gr_vtx1,&gr_vtx2);
  910. }
  911.  
  912. void fast_plot(GLcontext *ctx,GLuint first,GLuint last )
  913. {
  914.     struct vertex_buffer *VB = ctx->VB;
  915.     register GLuint i;
  916.  
  917.     if(VB->MonoColor) {
  918.         /* all same color */
  919.  
  920.         gr_vtx.r = DOSMesa->red;
  921.         gr_vtx.g = DOSMesa->green;
  922.         gr_vtx.b = DOSMesa->blue;
  923.  
  924.         for(i=first;i<last;i++) {
  925.             if(VB->ClipMask[i]==0) {
  926.                 gr_vtx.x = VB->Win[i][0];
  927.                 gr_vtx.y = FLIP(VB->Win[i][1]);
  928.             }
  929.         }
  930.     }
  931. }
  932.  
  933. /* TODO: */
  934. int vga_getpixel(x,y)
  935. {
  936. /*    return (int)SV_getPixel(x,y); */
  937.     fprintf(stderr,"vga_getpixel: Not implemented yet\n");
  938.     return 1;
  939. }
  940.  
  941. /* End of GLIDE section */
  942.  
  943. #endif // GLIDE
  944. /**********************************************************************/
  945. /*****                 Miscellaneous functions                    *****/
  946. /**********************************************************************/
  947.  
  948.  
  949. static void get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height )
  950. {
  951.    *width = DOSMesa->width = vga_getxdim();
  952.    *height = DOSMesa->height = vga_getydim();
  953. }
  954.  
  955.  
  956. /* Set current color index */
  957. static void set_index( GLcontext *ctx, GLuint index )
  958. {
  959.    DOSMesa->index = index;
  960.    /*vga_setcolor( index );*/
  961. }
  962.  
  963.  
  964. /* Set current drawing color */
  965. static void set_color( GLcontext *ctx,
  966.                        GLubyte red, GLubyte green,
  967.                        GLubyte blue, GLubyte alpha )
  968. {
  969.    DOSMesa->red = red;
  970.    DOSMesa->green = green;
  971.    DOSMesa->blue = blue;
  972.    vga_setrgbcolor( red, green, blue );
  973. }
  974.  
  975.  
  976. static void clear_index( GLcontext *ctx, GLuint index )
  977. {
  978.    /* TODO: Implements glClearIndex() */
  979. }
  980.  
  981.  
  982. static void clear_color( GLcontext *ctx,
  983.                          GLubyte red, GLubyte green,
  984.                          GLubyte blue, GLubyte alpha )
  985. {
  986.    /* TODO: Implements glClearColor() */
  987. }
  988.  
  989.  
  990. static void clear( GLcontext *ctx,
  991.                    GLboolean all,
  992.                    GLint x, GLint y, GLint width, GLint height )
  993. {
  994.    vga_clear();
  995. }
  996.  
  997.  
  998. static GLboolean set_buffer( GLcontext *ctx,
  999.                              GLenum mode )
  1000. {
  1001.    /* TODO: implement double buffering and use this function to select */
  1002.    /* between front and back buffers. */
  1003.    return GL_TRUE;
  1004. }
  1005.  
  1006.  
  1007.  
  1008.  
  1009. /**********************************************************************/
  1010. /*****            Write spans of pixels                           *****/
  1011. /**********************************************************************/
  1012.  
  1013.  
  1014. static void write_index_span( GLcontext *ctx,
  1015.                               GLuint n, GLint x, GLint y,
  1016.                               const GLuint index[],
  1017.                               const GLubyte mask[] )
  1018. {
  1019.    int i;
  1020.    y = FLIP(y);
  1021. #ifdef UNIVBE
  1022.     SV_beginPixel();
  1023. #endif
  1024.    for (i=0;i<n;i++,x++) {
  1025.       if (mask[i]) {
  1026. #ifdef UNIVBE
  1027.         SV_putPixelFast(x,y,current_color);
  1028. #else
  1029.          vga_setcolor( index[i] );
  1030.          vga_drawpixel( x, y );
  1031. #endif
  1032.       }
  1033.    }
  1034.  
  1035. #ifdef UNIVBE
  1036.     SV_endPixel();
  1037. #endif
  1038.  
  1039. }
  1040.  
  1041.  
  1042.  
  1043. static void write_monoindex_span( GLcontext *ctx,
  1044.                                   GLuint n, GLint x, GLint y,
  1045.                                   const GLubyte mask[] )
  1046. {
  1047.    int i;
  1048.    y = FLIP(y);
  1049.    /* use current color index */
  1050.    vga_setcolor( DOSMesa->index );
  1051. #ifdef UNIVBE
  1052.     SV_beginPixel();
  1053. #endif
  1054.    for (i=0;i<n;i++,x++) {
  1055.       if (mask[i]) {
  1056. #ifdef UNIVBE
  1057.             SV_putPixelFast(x,y,current_color);
  1058. #else
  1059.          vga_drawpixel( x, y );
  1060. #endif
  1061.       }
  1062.    }
  1063. #ifdef UNIVBE
  1064.     SV_endPixel();
  1065. #endif
  1066. }
  1067.  
  1068.  
  1069.  
  1070. static void write_color_span( GLcontext *ctx,
  1071.                               GLuint n, GLint x, GLint y,
  1072.                               const GLubyte red[], const GLubyte green[],
  1073.                               const GLubyte blue[], const GLubyte alpha[],
  1074.                               const GLubyte mask[] )
  1075. {
  1076.    int i;
  1077.    y=FLIP(y);
  1078. #ifdef UNIVBE
  1079.     SV_beginPixel();
  1080. #endif
  1081.    if (mask) {
  1082.       /* draw some pixels */
  1083.       for (i=0; i<n; i++, x++) {
  1084.          if (mask[i]) {
  1085. #ifdef UNIVBE
  1086.                 SV_putPixelFast(x,y,SV_rgbColor(red[i], green[i], blue[i]) );
  1087. #else
  1088.             vga_setrgbcolor( red[i], green[i], blue[i] );
  1089.             vga_drawpixel( x, y );
  1090. #endif
  1091.          }
  1092.       }
  1093.    }
  1094.    else {
  1095.       /* draw all pixels */
  1096.       for (i=0; i<n; i++, x++) {
  1097. #ifdef UNIVBE
  1098.             SV_putPixelFast(x,y,SV_rgbColor(red[i], green[i], blue[i]) );
  1099. #else
  1100.          vga_setrgbcolor( red[i], green[i], blue[i] );
  1101.          vga_drawpixel( x, y );
  1102. #endif
  1103.       }
  1104.    }
  1105. #ifdef UNIVBE
  1106.     SV_endPixel();
  1107. #endif
  1108. }
  1109.  
  1110.  
  1111.  
  1112. static void write_monocolor_span( GLcontext *ctx,
  1113.                                   GLuint n, GLint x, GLint y,
  1114.                                   const GLubyte mask[])
  1115. {
  1116.    int i;
  1117.    y=FLIP(y);
  1118. #ifdef UNIVBE
  1119.     SV_beginPixel();
  1120. #endif
  1121.    /* use current rgb color */
  1122.    vga_setrgbcolor( DOSMesa->red, DOSMesa->green, DOSMesa->blue );
  1123.    for (i=0; i<n; i++, x++) {
  1124.       if (mask[i]) {
  1125. #ifdef UNIVBE
  1126.             SV_putPixelFast(x,y,current_color);
  1127. #else
  1128.          vga_drawpixel( x, y );
  1129. #endif
  1130.       }
  1131.    }
  1132. #ifdef UNIVBE
  1133.     SV_endPixel();
  1134. #endif
  1135. }
  1136.  
  1137.  
  1138.  
  1139. /**********************************************************************/
  1140. /*****                 Read spans of pixels                       *****/
  1141. /**********************************************************************/
  1142.  
  1143.  
  1144. static void read_index_span( GLcontext *ctx,
  1145.                              GLuint n, GLint x, GLint y, GLuint index[])
  1146. {
  1147.    int i;
  1148.    y = FLIP(y);
  1149.    for (i=0; i<n; i++,x++) {
  1150.       index[i] = vga_getpixel( x, y );
  1151.    }
  1152. }
  1153.  
  1154.  
  1155.  
  1156. static void read_color_span( GLcontext *ctx,
  1157.                              GLuint n, GLint x, GLint y,
  1158.                              GLubyte red[], GLubyte green[],
  1159.                              GLubyte blue[], GLubyte alpha[] )
  1160. {
  1161.    int i;
  1162.    for (i=0; i<n; i++, x++) {
  1163.       /* TODO */
  1164.    }
  1165. }
  1166.  
  1167.  
  1168.  
  1169. /**********************************************************************/
  1170. /*****                  Write arrays of pixels                    *****/
  1171. /**********************************************************************/
  1172.  
  1173.  
  1174. static void write_index_pixels( GLcontext *ctx,
  1175.                                 GLuint n, const GLint x[], const GLint y[],
  1176.                                 const GLuint index[], const GLubyte mask[] )
  1177. {
  1178.    int i;
  1179. #ifdef UNIVBE
  1180.     SV_beginPixel();
  1181. #endif
  1182.    for (i=0; i<n; i++) {
  1183.       if (mask[i]) {
  1184. #ifdef UNIVBE
  1185.             SV_putPixelFast(x[i], FLIP(y[i]), index[i] );
  1186. #else
  1187.          vga_setcolor( index[i] );
  1188.          vga_drawpixel( x[i], FLIP(y[i]) );
  1189. #endif
  1190.       }
  1191.    }
  1192. #ifdef UNIVBE
  1193.     SV_endPixel();
  1194. #endif
  1195. }
  1196.  
  1197.  
  1198.  
  1199. static void write_monoindex_pixels( GLcontext *ctx,
  1200.                                     GLuint n,
  1201.                                     const GLint x[], const GLint y[],
  1202.                                     const GLubyte mask[] )
  1203. {
  1204.    int i;
  1205.    /* use current color index */
  1206.    vga_setcolor( DOSMesa->index );
  1207. #ifdef UNIVBE
  1208.     SV_beginPixel();
  1209. #endif
  1210.    for (i=0; i<n; i++) {
  1211.       if (mask[i]) {
  1212. #ifdef UNIVBE
  1213.             SV_putPixelFast(x[i], FLIP(y[i]), DOSMesa->index);
  1214. #else
  1215.          vga_drawpixel( x[i], FLIP(y[i]) );
  1216. #endif
  1217.       }
  1218.    }
  1219. #ifdef UNIVBE
  1220.     SV_endPixel();
  1221. #endif
  1222. }
  1223.  
  1224.  
  1225.  
  1226. static void write_color_pixels( GLcontext *ctx,
  1227.                                 GLuint n, const GLint x[], const GLint y[],
  1228.                                 const GLubyte r[], const GLubyte g[],
  1229.                                 const GLubyte b[], const GLubyte a[],
  1230.                                 const GLubyte mask[] )
  1231. {
  1232.    int i;
  1233. #ifdef UNIVBE
  1234.     SV_beginPixel();
  1235. #endif
  1236.    for (i=0; i<n; i++) {
  1237.       if (mask[i]) {
  1238. #ifdef UNIVBE
  1239.             SV_putPixelFast(x[i], FLIP(y[i]), SV_rgbColor(r[i], g[i], b[i]) );
  1240. #else
  1241.          vga_setrgbcolor( r[i], g[i], b[i] );
  1242.          vga_drawpixel( x[i], FLIP(y[i]) );
  1243. #endif
  1244.       }
  1245.    }
  1246. #ifdef UNIVBE
  1247.     SV_endPixel();
  1248. #endif
  1249. }
  1250.  
  1251. static void write_monocolor_pixels( GLcontext *ctx,
  1252.                                     GLuint n,
  1253.                                     const GLint x[], const GLint y[],
  1254.                                     const GLubyte mask[] )
  1255. {
  1256.    int i;
  1257.    /* use current rgb color */
  1258.    vga_setrgbcolor( DOSMesa->red, DOSMesa->green, DOSMesa->blue );
  1259. #ifdef UNIVBE
  1260.     SV_beginPixel();
  1261. #endif
  1262.    for (i=0; i<n; i++) {
  1263.       if (mask[i]) {
  1264. #ifdef UNIVBE
  1265.             SV_putPixelFast(x[i], FLIP(y[i]), current_color );
  1266. #else
  1267.          vga_drawpixel( x[i], FLIP(y[i]) );
  1268. #endif
  1269.       }
  1270.    }
  1271. #ifdef UNIVBE
  1272.     SV_endPixel();
  1273. #endif
  1274. }
  1275.  
  1276. /**********************************************************************/
  1277. /*****                   Read arrays of pixels                    *****/
  1278. /**********************************************************************/
  1279.  
  1280. /* Read an array of color index pixels. */
  1281. static void read_index_pixels( GLcontext *ctx,
  1282.                                GLuint n, const GLint x[], const GLint y[],
  1283.                                GLuint index[], const GLubyte mask[] )
  1284. {
  1285.    int i;
  1286.    for (i=0; i<n; i++) {
  1287.       index[i] = vga_getpixel( x[i], FLIP(y[i]) );
  1288.    }
  1289. }
  1290.  
  1291.  
  1292.  
  1293. static void read_color_pixels( GLcontext *ctx,
  1294.                                GLuint n, const GLint x[], const GLint y[],
  1295.                                GLubyte red[], GLubyte green[],
  1296.                                GLubyte blue[], GLubyte alpha[],
  1297.                                const GLubyte mask[] )
  1298. {
  1299.    /* TODO */
  1300. }
  1301.  
  1302. static void DOSmesa_setup_DD_pointers( GLcontext *ctx )
  1303. {
  1304.    /* Initialize all the pointers in the DD struct.  Do this whenever */
  1305.    /* a new context is made current or we change buffers via set_buffer! */
  1306.  
  1307.    ctx->Driver.UpdateState = DOSmesa_setup_DD_pointers;
  1308.  
  1309.    ctx->Driver.ClearIndex = clear_index;
  1310.    ctx->Driver.ClearColor = clear_color;
  1311.    ctx->Driver.Clear = clear;
  1312.  
  1313.    ctx->Driver.Index = set_index;
  1314.    ctx->Driver.Color = set_color;
  1315.  
  1316.    ctx->Driver.SetBuffer = set_buffer;
  1317.    ctx->Driver.GetBufferSize = get_buffer_size;
  1318.  
  1319.    ctx->Driver.PointsFunc = choose_points_function();
  1320.    ctx->Driver.LineFunc = choose_line_function();
  1321.    ctx->Driver.TriangleFunc = choose_triangle_function();
  1322.  
  1323.  
  1324.    /* Pixel/span writing functions: */
  1325.    /* TODO: use different funcs for 8, 16, 32-bit depths */
  1326.    ctx->Driver.WriteColorSpan       = write_color_span;
  1327.    ctx->Driver.WriteMonocolorSpan   = write_monocolor_span;
  1328.    ctx->Driver.WriteColorPixels     = write_color_pixels;
  1329.    ctx->Driver.WriteMonocolorPixels = write_monocolor_pixels;
  1330.    ctx->Driver.WriteIndexSpan       = write_index_span;
  1331.    ctx->Driver.WriteMonoindexSpan   = write_monoindex_span;
  1332.    ctx->Driver.WriteIndexPixels     = write_index_pixels;
  1333.    ctx->Driver.WriteMonoindexPixels = write_monoindex_pixels;
  1334.  
  1335.    /* Pixel/span reading functions: */
  1336.    /* TODO: use different funcs for 8, 16, 32-bit depths */
  1337.    ctx->Driver.ReadIndexSpan = read_index_span;
  1338.    ctx->Driver.ReadColorSpan = read_color_span;
  1339.    ctx->Driver.ReadIndexPixels = read_index_pixels;
  1340.    ctx->Driver.ReadColorPixels = read_color_pixels;
  1341. }
  1342.  
  1343. /*
  1344.  * Create a new VGA/Mesa context and return a handle to it.
  1345.  */
  1346. DOSMesaContext DOSMesaCreateContext( void )
  1347. {
  1348.    DOSMesaContext ctx;
  1349.    GLboolean rgb_flag;
  1350.    GLfloat redscale, greenscale, bluescale, alphascale;
  1351.    GLboolean db_flag = GL_FALSE;
  1352.    GLboolean alpha_flag = GL_FALSE;
  1353.    int colors;
  1354.    GLint index_bits;
  1355.    GLint redbits, greenbits, bluebits, alphabits;
  1356.  
  1357. #if !defined(UNIVBE) && !defined(GLIDE) && !defined(MGL)
  1358.     video_buffer = (unsigned char *) malloc( vga_getxdim() * vga_getydim() );
  1359.  
  1360.     memset(video_buffer,0, vga_getxdim() * vga_getydim() );
  1361.  
  1362.     memset(rgbtable,0,sizeof( rgbtable ) );
  1363. #endif
  1364.  
  1365. #if defined( DJGPP ) && !defined(UNIVBE) && !defined(GLIDE)
  1366.     dos_seg = _go32_conventional_mem_selector();
  1367. #endif
  1368.  
  1369.    /* determine if we're in RGB or color index mode */
  1370.    colors = vga_getcolors();
  1371.    if (colors==32768) {
  1372.       rgb_flag = GL_TRUE;
  1373.       redscale = greenscale = bluescale = alphascale = 255.0;
  1374.       redbits = greenbits = bluebits = 8;
  1375.       alphabits = 0;
  1376.       index_bits = 0;
  1377.    }
  1378.    else if (colors==256) {
  1379.       rgb_flag = GL_FALSE;
  1380.       redscale = greenscale = bluescale = alphascale = 0.0;
  1381.       redbits = greenbits = bluebits = alphabits = 0;
  1382.       index_bits = 8;
  1383.    }
  1384.    else {
  1385.         restore_video_mode();
  1386.       fprintf(stderr,"[%d] >16 bit color not implemented yet!\n",colors);
  1387.       return NULL;
  1388.    }
  1389.  
  1390.    ctx = (DOSMesaContext) calloc( 1, sizeof(struct DOSmesa_context) );
  1391.    if (!ctx) {
  1392.       return NULL;
  1393.    }
  1394.  
  1395.    ctx->gl_vis = gl_create_visual( rgb_flag,
  1396.                                    alpha_flag,
  1397.                                    db_flag,
  1398.                                    16,   /* depth_size */
  1399.                                    8,    /* stencil_size */
  1400.                                    16,   /* accum_size */
  1401.                                    index_bits,
  1402.                                    redscale,
  1403.                                    greenscale,
  1404.                                    bluescale,
  1405.                                    alphascale,
  1406.                                    redbits, greenbits,
  1407.                                    bluebits, alphabits);
  1408.  
  1409.    ctx->gl_ctx = gl_create_context( ctx->gl_vis,
  1410.                                     NULL,  /* share list context */
  1411.                                     (void *) ctx
  1412.                                   );
  1413.  
  1414.    ctx->gl_buffer = gl_create_framebuffer( ctx->gl_vis );
  1415.  
  1416.    ctx->index = 1;
  1417.    ctx->red = ctx->green = ctx->blue = 255;
  1418.  
  1419.    ctx->width = ctx->height = 0;  /* temporary until first "make-current" */
  1420.  
  1421.    return ctx;
  1422. }
  1423.  
  1424. /*
  1425.  * Destroy the given VGA/Mesa context.
  1426.  */
  1427. void DOSMesaDestroyContext( DOSMesaContext ctx )
  1428. {
  1429.    if (ctx) {
  1430.       gl_destroy_visual( ctx->gl_vis );
  1431.       gl_destroy_context( ctx->gl_ctx );
  1432.       gl_destroy_framebuffer( ctx->gl_buffer );
  1433.       free( ctx );
  1434.       if (ctx==DOSMesa) {
  1435.          DOSMesa = NULL;
  1436.       }
  1437.    }
  1438. }
  1439.  
  1440.  
  1441.  
  1442. /*
  1443.  * Make the specified VGA/Mesa context the current one.
  1444.  */
  1445. void DOSMesaMakeCurrent( DOSMesaContext ctx )
  1446. {
  1447.    DOSMesa = ctx;
  1448.    gl_make_current( ctx->gl_ctx, ctx->gl_buffer );
  1449.    DOSmesa_setup_DD_pointers( ctx->gl_ctx );
  1450.  
  1451.    if (ctx->width==0 || ctx->height==0) {
  1452.       /* setup initial viewport */
  1453.       ctx->width = vga_getxdim();
  1454.       ctx->height = vga_getydim();
  1455.       gl_Viewport( ctx->gl_ctx, 0, 0, ctx->width, ctx->height );
  1456.    }
  1457. }
  1458.  
  1459.  
  1460.  
  1461. /*
  1462.  * Return a handle to the current VGA/Mesa context.
  1463.  */
  1464. DOSMesaContext DOSMesaGetCurrentContext( void )
  1465. {
  1466.    return DOSMesa;
  1467. }
  1468.  
  1469.  
  1470. /*
  1471.  * Swap front/back buffers for current context if double buffered.
  1472.  */
  1473. void DOSMesaSwapBuffers( void )
  1474. {
  1475. #if !defined(UNIVBE)
  1476. /* Assume double buffering is available if in UNIVBE,
  1477.    if it isn`t its taken care of anyway */
  1478. //   if (DOSMesa->gl_vis->DBflag)
  1479. #endif
  1480.      {
  1481.       vga_flip();
  1482.    }
  1483. }
  1484.  
  1485.  
  1486. #else
  1487.  
  1488. /*
  1489.  * Need this to provide at least one external definition when DOS is
  1490.  * not defined on the compiler command line.
  1491.  */
  1492.  
  1493. int gl_DOS_dummy_function(void)
  1494. {
  1495.    return 0;
  1496. }
  1497.  
  1498. #endif  /*DOS*/
  1499.  
  1500.